{extends file='layout/admin.html'}

{block name='title'}{if $data}Edit{else}Add{/if} Asset  - Geek-Zoo CMS{/block}

{block name='content'}

{if $is_my_asset}
{$url = 'my_asset'}
{else}
{$url = 'asset_manage'}
{/if}
<script type="text/javascript" src="js/swfupload/swfupload.js"></script>
<script type="text/javascript" src="js/upload_file.js"></script>
	
    		<div class="clearfix sub_nav t_border"><span class="btn fr"><a href="admin/{$url}.html?cate_id={$smarty.get.cate_id}">Cancel</a></span><span class="btn fr"><a href="" class="save">Save</a></span></div>
    		<form action="admin/{$url}/add.html" method="POST" name="form1">
					<input type="hidden" name="save_continue" value="0">
					<input type="hidden" name="id" value="{$data.id}">
					<input type="hidden" name="info[cate_group_id]" value="{if $data.cate_group_id}{$data.cate_group_id}{else}{$smarty.get.cate_id}{/if}">
					<input type="hidden" name="info[language]" value="{if $data.language}{$data.language}{else}{$smarty.get.lang}{/if}">
				<table width="100%" border="0" cellspacing="0" cellpadding="0" class="content_table">
    			<thead>
    				<tr style="height: 20px">
    					<th class="left"></th>
    					<th class="right"></th>
    				</tr>
    			</thead>
    			<tbody>
    				<tr>
    					<td style="width: 30%" class="left_label large tar">Title</td>
    					<td class="right_label"><input type="text" class="input_text w500" name="info[title]" value="{$data.title}" /></td>
    				</tr>
						{if $smarty.get.cate_id == 3 || $data.img}
    				<tr>
    					<td style="width: 30%; height 60px;" class="left_label large tar">Thumbnail image</td>
    					<td class="right_label">
									<div class="img_add">
										{if $data.img}
											<img src="pic/200/200?file={$data.img}" />
										{/if}
									</div>
								<input type="hidden" name="info[img]" value="{$data.img}" id="info[img]">
								<a href="#" class="upload_file">UPLOAD FILE</a>
    					</td>
    				</tr>
						{/if}
    				<tr>
    					<td style="width: 30%" class="left_label large tar">Description</td>
    					<td class="right_label">
    						<textarea name="info[description]" id="" cols="30" rows="10" class="w500">{$data.description}</textarea>
    					</td>
    				</tr>

    			</tbody>
    		</table>
    		<div class="clearfix sub_nav t_border"><span class="btn fr"><a href="admin/{$url}.html?cate_id={$smarty.get.cate_id}">Cancel</a></span><span class="btn fr"><a href="" class="save">Save</a></span></div>
  		</form>
<script type="text/javascript" charset="utf-8">
dialog_title = 'Manage Asset';
var PHPSESSID = '{$smarty.cookies.PHPSESSID}';

$('.upload_file').click(function(){
  
  upload_file(function(file){
		if (file.ext == 'jpg' || file.ext == 'jpeg' || file.ext == 'gif' || file.ext == 'png') {
			 $(".img_add").html('<img src="pic/200/200?file='+file.file_path+'" />');
			 $("input[name=info[img]]").val(file.file_path);
		}else{
			show_msg('not a img');
		}
  });
  
  return false;
});

$(".save").click(function(){
	if(!check_info()){
		return false;
	}

	$("form[name=form1]").submit();
	return false;
});

$(".save_continue").click(function(){
	if(!check_info()){
		return false;
	}

	$("form[name=form1]").submit();
	return false;
});

$(".add_a").click(function(){
	$("tbody").append('<tr>\
		<td style="width: 30%;" class="left_label large tar"><input type="text" class="input_text" name="append[key][]" style="width:150px;" /></td>\
		<td class="right_label"><input type="text" class="input_text" name="append[value][]" style="width:400px;" /><span class="btn fr"><a href="javascript://" class="rm_up">Delete</a></span></td>\
	</tr>');
});

$('.rm_up').live('click', function(){
  $(this).parent().parent().parent().remove();
});

function check_info () {
	var title = $('input[name=info[title]]');
	if (!title.val()) {
		show_msg('title is empty', function(){
		  title.focus();
		});
		return false;
	};
	return true;
}

</script>
{/block}
